package com.max.xihu.patterns.responsible;

/**
 * @Author: Max
 * @Date: 2020-09-15 23:26
 * @Description:
 */
public abstract class Handler {

    private Handler nextHandler;

    public final Response handler(RequstContext context){
        Response object = null;
        if (this.getHandlerLevel().equals(context.getLevel())){
            object = this.process(context);
        }else{
            if (this.nextHandler != null){
                object = this.nextHandler.handler(context);
            }else{
                //没有适当的处理者，则其他业务处理
            }
        }
        return object;
    }

    public void setNext(Handler handler){
        this.nextHandler = handler;
    }

    protected abstract Level getHandlerLevel();

    protected abstract Response process(RequstContext context);
}
